package com.guigu.xxljobdemo.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class SimpleXxlJob {
    
    private static Logger logger = LoggerFactory.getLogger(SimpleXxlJob.class);
    
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        String jobParam = XxlJobHelper.getJobParam();
        
        // 使用多种方式输出日志确保能看到
        System.out.println("===System.out.println=== 执行定时任务,执行时间:" + new Date());
        logger.info("===Logger.info=== 执行定时任务,执行时间:{}, 参数信息: {}", new Date(), jobParam);
        XxlJobHelper.log("===XxlJobHelper.log=== 执行定时任务,执行时间:{}, 参数信息: {}", new Date(), jobParam);
        
        System.out.flush(); // 强制刷新输出流
    }
}